#pragma once

#include <string>
#include <iostream>
#include <sqlite3.h>
#include "Buffer.h"


//SENSORS
#define HUMITURE_SENSOR_DBNAME "humiture_sensor.db"
#define HUMITURE_SENSOR_DATA_TABLE_NAME "humiture"
#define HUMITURE_SENSOR_CONFIG_TABELE_NAME "humiture_sensor_config"
#define HUMITURE_DESCRIPTION "温湿度传感器 记录温湿度"

#define LASER_SENSOR_DBNAME "laser_sensor.db"
#define LASER_SENSOR_DATA_TABLE_NAME  "hasObstacles"
#define LASER_SENSOR_CONFIG_TABELE_NAME "laser_sensor_config"
#define LASER_DESCRIPTION "激光传感器 判断是否有障碍物遮挡"



using std::string;
using namespace std;

#define Clock 27
#define Address 28
#define DataOut 29

class SensorConfig
{
public:
	SensorConfig() { sample = 1; };
	~SensorConfig() {};

	//采样时间
	void setSample(int sample) { this->sample = sample; };
	int getSample() { return this->sample; };
	SensorConfig operator=(const SensorConfig&);
private:
	int sample;

};

class Sensor
{
protected:
	//传感器ID
	int deviceID;

	//将传感器信息记录进表

public:

	SensorConfig config;
	//缓冲区
	Buffer buffer;
	
	Sensor(int deviceID,  std::string dbName, std::string dataTableName, std::string configTableName);

	~Sensor();
	//ID
	int getDeviceID() { return this->deviceID; };
	void setConfig(const SensorConfig& config);

	//从数据库中读取配置
	virtual SensorConfig readConfigFromBuffer() =0;
	//将配置写入数据库中
	virtual void writeConfigToBuffer(SensorConfig config) = 0;

	//记录传感器数据
	virtual void recordSensorData() = 0;
	//获取传感器数据
	virtual void readSensorData() = 0;
	
	unsigned int ADC_Read(unsigned char channel);

};

